print("------------ 字典的创建 ------------")
var dict1 = Dictionary<String, Int>()
var dict2 = [String: Int]()
var dict3: Dictionary<String, Int> = ["zhangsan": 18, "lisi": 19]
print(dict1)
print(dict2)
print(dict3)
print(dict3.count)
print(dict3.isEmpty)

print("------------ 遍历 ------------")
for (name, age) in dict3 {
    print("\(name)的年龄是\(age)")
}

print("------------ 字典的常见操作 ------------")
print("------------ 添加元素 ------------")
// 方法1
dict3["wangwu"] = 20
print(dict3)
// 方法2
dict3.updateValue(21, forKey: "zhaoliu")
print(dict3)
print("------------ 移除元素 ------------")
// 方法1
dict3["wangwu"] = nil
print(dict3)
// 方法2
dict3.removeValue(forKey: "zhaoliu")
print(dict3)

print("------------ 合并两个字典 ------------")
var dict4 = ["zhangsan": 18, "lisi": 19]
var dict5 = ["zhaoliu": 21, "songqi": 22]
// current表示如果碰到相同key的时候用ditc4的, 如果要用dict5的话就互换current和_的位置
dict4.merge(dict5) { current, _ in
    current
}
print(dict4)

